package com.dingding.queue.queue.producer;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendResult;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.common.core.util.ToolUtil;

/**
 * 
 * @ClassName: PushProducer 
 * @Description:消息推送生产者
 * @author CHEHAUNBO 
 * @date 2016年6月7日 下午2:53:31
 * 
 */
@SuppressWarnings("all")
@Component("pushProducer")
public class PushProducer implements IProducer {

	@Resource(name = "producerFactory")
	private ProducerFactory producerFactory;

	private static final Logger log = Logger.getLogger(PushProducer.class);

	@Override
	public boolean send(String content) {

		long currentTime = System.currentTimeMillis();
		
		Message msg = new Message(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.PUSH.toString(),
				content.getBytes());
		
		try {
			SendResult sendResult = producerFactory.producer.send(msg);
			if (sendResult != null && ToolUtil.isNotBlank(sendResult.getMessageId())) { // 发送成功
				return true;
			}
		} catch (Exception e) {
			log.error("发送推送消息到队列中出现异常！PushProducer : send()", e);
		}

		return false;

	}

}
